package com.banyuan.servlet.user;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/user/logout")
public class LogOutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 退出的意思就是把存的Session 给清空
        HttpSession session = req.getSession();
        session.invalidate();   // 把sessin清空

        //再让他跳转到 登陆页面,并且要前段显示，让用户登陆,因为msg在登陆的jsp，前面已经写过了，直接利用
        req.setAttribute("msg","你还没有登陆，请登陆");
        req.getRequestDispatcher("/user/log.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
